<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 3.6</title>
</head>

<body>
<?php	
	function XuatMang($mang)
	{
		for($i=0;$i<count($mang);$i++)
		{
				$kq.=$mang[$i].",";
		}
		return $kq;
	}
	if(isset($_POST['mangnhap']) && isset($_POST['timso']))
	{
		$sotim=$_POST['timso'];
		$chuoi=$_POST['mangnhap'];
		$mang=explode(",",$chuoi);
		$mangxuat=XuatMang($mang);
		$vitri=array_search($sotim,$mang);
		$kq=$vitri!==false?"Tìm thấy số $sotim tại vị trí ".($vitri+1)." trong mảng":"Không tìm thấy số $sotim trong mảng";
	}
?>
<form id="form1" name="form1" method="post" action="Bai3_6.php">
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr bgcolor="#006666" style="text-align: center; font-weight: bold; font-style: italic; color: #FFF; font-size: 24px;">
      <td colspan="2">TÌM KIẾM</td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#99FFFF">Nhập mảng:</td>
      <td nowrap="nowrap" bgcolor="#99FFFF"><input name="mangnhap" type="text" id="mangnhap" value="<?php echo $_POST['mangnhap'];?>" size="98%" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#99FFFF">Nhập số cần tìm:</td>
      <td nowrap="nowrap" bgcolor="#99FFFF"><input name="timso" type="text" id="timso" value="<?php echo $_POST['timso'];?>" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#99FFFF">&nbsp;</td>
      <td nowrap="nowrap" bgcolor="#99FFFF"><input style="background-color:#36F" type="submit" name="button" id="button" value="Tìm kiếm" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#99FFFF">Mảng:</td>
      <td nowrap="nowrap" bgcolor="#99FFFF"><input name="mangxuat" type="text" id="mangxuat" value="<?php echo $mangxuat;?>" size="98%" /></td>
    </tr>
    <tr>
      <td nowrap="nowrap" bgcolor="#99FFFF">Kết quả tìm kiếm:</td>
      <td nowrap="nowrap" bgcolor="#99FFFF"><input style="background-color:#6CC; color:#F00; font-weight:bold" name="kq" type="text" disabled="disabled" id="kq" value="<?php echo $kq;?>" size="98%" /></td>
    </tr>
    <tr bgcolor="#009999" style="text-align: center">
      <td colspan="2">(Các phần tử trong mảng sẽ cách nhau bằng dấu &quot;,&quot;)</td>
    </tr>
  </table>
</form>
</body>
</html>